package com.sc.auction.goods.controller;


import com.sc.auction.common.exception.AuctionException;
import com.sc.auction.common.util.R;
import com.sc.auction.goods.pojo.Goodstype;
import com.sc.auction.goods.service.GoodstypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lsc
 * @since 2020-09-01
 */

@CrossOrigin
@RestController
@RequestMapping("/goods/goodstype")
public class GoodstypeController {


    @Autowired
    private GoodstypeService goodstypeService;

    @ApiOperation("查询所有分类")
    @GetMapping("/getTypes")
    public R  getTypes() throws AuctionException {
        List<Goodstype> list = goodstypeService.list();
        if (list!=null&&list.size()>0){
            return R.ok().data("types",list);
        }else {
            throw new AuctionException(201,"未查询到分类信息");
        }
    }
    @ApiOperation("增加分类")
    @PostMapping("/addType")
    public R addType(Goodstype goodstype) throws AuctionException {
        boolean save = goodstypeService.save(goodstype);
        if (save){
            return R.ok();
        }else {
            throw new AuctionException(201,"增加分类失败");
        }
    }
}

